
package view;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 *
 * @author john
 */
public class ReportResultDialog extends Stage{
    
    private final Group root;
    private final Scene scene;
    private final GridPane grid;
    private final Button confirmB;
    private final Label mainL;
    
    public ReportResultDialog(GridPane container, Stage owner, String title, String message, boolean cleanFields){
        super();
        initOwner(owner);
        initModality(Modality.APPLICATION_MODAL);
        root=new Group();
        scene=new Scene(root);
        scene.setFill(Color.WHITE);
        setScene(scene);
        grid=new GridPane();
        grid.setPadding(new Insets(20));
        grid.setHgap(10);
        grid.setVgap(6);
        mainL=new Label(message);
        GridPane.setHalignment(mainL, HPos.LEFT);
        mainL.setMinWidth(200);
        confirmB=new Button("Aceptar");
        confirmB.setOnAction(confirmResult(container, this, cleanFields));
        GridPane.setHalignment(confirmB, HPos.CENTER);
        GridPane.setMargin(confirmB, new Insets(10, 0, 0, 0));
        grid.add(mainL, 0, 0);
        grid.add(confirmB, 0, 1);
        root.getChildren().add(grid);
        setTitle(title);
        setOpacity(0.95);
        setResizable(false);
    }
    
    private EventHandler<ActionEvent> confirmResult(final GridPane container,final Stage reportResultDialog, final boolean cleanFields){
        return new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                reportResultDialog.close();
                if(cleanFields)
                    ((StatsPane)container).cleanFields();
            }
        };
    }
    
}